using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CanDienTu_WS.Models;
using System.Runtime.Serialization;

namespace CanDienTu_WS.DTO
{
    [DataContract]
	public class DuLieuDTO
	{
        [DataMember]
		public int ID { get; set; }

        [DataMember]
		public int IDGio { get; set; }

        [DataMember]
		public float KhoiLuong { get; set; }

        [DataMember]
		public string ThoiDiemDo { get; set; }

        public static DuLieuDTO Translate(DuLieu Entity)
        {
            if (Entity != null)
            {
                var dto = new DuLieuDTO
                {
                    ID = Entity.ID,
                    IDGio = Entity.IDGio.Value,
                    KhoiLuong = Entity.KhoiLuong.Value,
                    ThoiDiemDo = String.Format("{0:dd/MM/yyyy HH:mm:ss}", Entity.ThoiDiemDo.Value)
                };
                return dto;
            }
            return null;
        }

        public static DuLieu Reverse(DuLieuDTO obj)
        {
            string[] supportedFormats = new String[] { "dd/MM/yyyy HH:mm:ss", "MM/dd/yyyy HH:mm:ss", "MM/dd/yy HH:mm:ss", "ddMMMyyyy", "dMMMyyyy HH:mm:ss" };
            DateTime thoidiemdo = DateTime.ParseExact(
                obj.ThoiDiemDo, supportedFormats,
                System.Globalization.CultureInfo.CurrentCulture,
                System.Globalization.DateTimeStyles.None);
            var entity = new DuLieu
            {
                ID = obj.ID,
                IDGio = obj.IDGio,
                KhoiLuong = obj.KhoiLuong,
                ThoiDiemDo = thoidiemdo
            };
            return entity;
        }
	}
}